import QtQuick 2.9
import QtQuick.Controls 2.5

import "../widgets" as Widgets

Rectangle {
    id: root
    color: "#99333333"

    property int eventCode: 0 //0 = set date from, 1 = set date to

    signal clickedYes()
    signal clickedNo()

    function show(date, ecode) {
        _date = date ? date: new Date()
        eventCode = ecode

        //
        sbYear.value = _date.getFullYear()
        sbMonth.value = _date.getMonth()
        sbDay.value = _date.getDate()

        root.visible = true
    }

    function getDate() {
        var dt = new Date(_date);
        dt.setFullYear(_year)
        dt.setMonth(_month)
        dt.setDate(_day)
        return new Date(dt)
    }

    property date _date
    property alias _year: sbYear.value
    property alias _month: sbMonth.value
    property alias _day: sbMonth.value

    ///////////////////////////////////////////////

    MouseArea {
        anchors.fill: parent
        acceptedButtons: Qt.AllButtons
        hoverEnabled: true
        onClicked: {}
        onPressed: {}
        onReleased: {}
        onWheel: {}
    }

    Rectangle {
        id: layoutContent
        width: root.width * 0.6
        height: root.height * 0.4
        anchors.centerIn: parent

        color: "#f1f1f1"
        radius: 10

        Column {
            width: parent.width
            height: parent.height
            Text {
                id: txtTitle
                width: parent.width
                height: layoutContent.height * 0.2
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                font.pixelSize: height * 0.5
                text: qsTr("选择日期")
            }
            Rectangle {
                width: parent.width; height: 1
                color: "#999"
            }
            Item {
                width: parent.width
                height: layoutContent.height * 0.6

                Row {
                    width: parent.width
                    height: parent.height
                    spacing: width * 0.1
                    leftPadding: spacing

                    Widgets.SpinBox {
                        id: sbYear
                        width: parent.width * 0.2
                        height: parent.height * 0.5
                        anchors.verticalCenter: parent.verticalCenter
                        min: 1970
                        max: 2019
                        value: 2019
                    }

                    Widgets.SpinBox {
                        id: sbMonth
                        width: parent.width * 0.2
                        height: parent.height * 0.5
                        anchors.verticalCenter: parent.verticalCenter
                        min: 1
                        max: 12
                        value: 1

                    }

                    Widgets.SpinBox {
                        id: sbDay
                        width: parent.width * 0.2
                        height: parent.height * 0.5
                        anchors.verticalCenter: parent.verticalCenter
                        min: 1
                        max: 31
                        value: 1
                    }
                }
            }
            Rectangle {
                width: parent.width; height: 1
                color: "#999"
            }

            //...底部按钮
            Row {
                width: parent.width
                height: layoutContent.height * 0.2

                Widgets.FlatButton {
                    width: parent.width * 0.5
                    height: parent.height
                    text: qsTr("取消")
                    textColor: "#2E75B6"
                    backgroundColor: "transparent"
                    onClicked: {
                        root.visible = false
                        clickedNo()
                    }
                }

                Rectangle {
                    width: 1
                    height: parent.height
                    color: "#666"
                }

                Widgets.FlatButton {
                    width: parent.width * 0.5
                    height: parent.height
                    text: qsTr("确定")
                    textColor: "#2E75B6"
                    backgroundColor: "transparent"
                    onClicked: {
                        root.visible = false
                        clickedYes()
                    }
                }

            }//...底部按钮
        }
    }
}
